package cn.com.header.zbpk.account.entity;

import cn.com.header.zbpk.model.AuthorityMode;
import cn.com.header.zbpk.model.BaseTree;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Set;

/**
 * 权限资源
 *
 * @author zhangrt
 * @date 2017/9/11
 * @time 19:16
 */
@Getter
@Setter
@ToString(callSuper = true)
public class Authority extends BaseTree<String, Authority> {

    /**
     * 公共的权限ID，匹配每个用户具有的权限。地址无需存储到数据库，直接配置即可
     * 注意：该ID值不应该写入权限资源表
     */
    public static final String COMMON_AUTH_ACCESS_ID = "COMMON_AUTH_ACCESS";

    /**
     * 科目管理权限ID
     */
    public static final String SUBJECT_MANAGE = "SUBJECT_MANAGE";

    @JSONField(ordinal = 4)
    private Integer level;
    @JSONField(ordinal = 3)
    private String name;
    private Integer serialNumber;
    private AuthorityMode mode;
    private Set<String> assets;

    @Override
    public int hashCode() {
        if (getId() != null) {
            return getId().hashCode();
        }
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (getId() != null && obj instanceof Authority) {
            Authority authority = (Authority) obj;
            return getId().equals(authority.getId());
        }
        return super.equals(obj);
    }
}
